clear
set more off


foreach k in ertc ertc_amendment {
	use "$statadir/explain_`k'", clear
	tostring r2_a, replace format(%6.3f) force
	rename r2_a r2_`k'
	tempfile d`k'
	qui save `d`k'', replace
}
	
use `dertc', clear
merge 1:1 spec using `dertc_amendment', nogen

local d1 "Quarter fixed effects"
local d2 "Add interaction with firm size fixed effects"
local d3 "Add interaction with 3-digit NAICS"
local d4 "Add interaction with 6-digit NAICS"
local d5 "Add preparer fixed effects"

sort spec


cap file close myfile
file open myfile using "$outdir/tables/explain_all.tex", write replace

*************
*	Header	*
*************

file write myfile " & \multicolumn{3}{c}{Adjusted \$R^2\$ for take-up on...} \\ "
file write myfile " \cmidrule(lr){2-4} "
file write myfile " & original returns & amended returns \\ "
file write myfile " & (1) & (2) \\ "
file write myfile " \hline "

forval i = 1/5 {

	
	
	file write myfile " `d`i'' & `=r2_ertc[`i']' & `=r2_ertc_amendment[`i']' & \\ "
	

}




cap file close myfile

	

